﻿using BW.IBLL;
using BW.IDAL;
using BW.Model;

namespace BW.BLL
{
    public class BaseBLL:IBaseBLL
    {
        IBAseDAL<RoomNumber> dal;
        IBAseDAL<RoomType> del;
        public BaseBLL(IBAseDAL<RoomNumber> dal, IBAseDAL<RoomType> del)
        {
            this.dal = dal;
            this.del = del;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public async Task<int> Add(RoomNumber t)
        {
            return await dal.GetAdd(t);
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="totalcount">总条数</param>
        /// <param name="totalpage">总页数</param>
        /// <param name="pageindex">共几页</param>
        /// <param name="pagesize">共几条</param>
        /// <returns></returns>
        public IQueryable<DTO> GetShow(out int totalcount, out int totalpage, int pageindex = 1, int pagesize = 2)
        {
            var list = dal.GetAll().Join(del.GetAll(), a => a.Roomid, b => b.Id, (a, b) => new DTO
            {
                Id = a.Id,
                Roomnum = a.Roomnum,
                Roomid = a.Roomid,
                RoomName = b.RoomName
            });
            totalcount = list.Count();
            totalpage = (int)Math.Ceiling(totalcount *1.0/pagesize);
            list=list.OrderBy(x=>x.Id).Skip((pageindex-1)*pagesize).Take(pagesize);
            return list;
        }
        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        
        public async Task<int> RoomAdd(List<RoomNumber> list)
        {
            return await dal.AddListAsync(list);
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public IQueryable<RoomType> roomTypes()
        {
            return del.GetAll();
        }
    }
}
